#include <stdio.h>
// 结构体作为参数传递
struct stu
{
	char *name;
	float age;
	short int sex;
} stus[] = {
	{"rty001", 12.3, 1},
	{"rty002", 12.1, 1},
	{"rty003", 12.0, 1}};
void average(struct stu *ps, int len)
{
	int i, num_140 = 0;
	float average, sum = 0;
	for (i = 0; i < len; i++)
	{
		sum += (ps + i)->age;
		if ((ps + i)->age < 140)
			num_140++;
	}
	printf("sum=%.2f\naverage=%.2f\nnum_140=%d\n", sum, sum / 5, num_140);
};
int main()
{
	// 结构体
	struct dian
	{
		char *name;
		int age;
		short int sex;
	} dian1;

	dian1.name = "zhangds";
	dian1.age = 18;
	dian1.sex = 1;
	printf("姓名:%s, 年龄:%d, 性别:%hd \n", dian1.name, dian1.age, dian1.sex);

	// 初始化结构体
	struct p1
	{
		char *name;
		int age;
		short int sex;
	} p3 = {"zhudachang", 18, 0};
	printf("姓名:%s, 年龄:%d, 性别:%hd \n", p3.name, p3.age, p3.sex);

	// 数组结构体
	struct a1
	{
		char *name;
		int age;
		short int sex;
	} a2[4] = {
		{"zhangds001", 18, 1},
		{"zhangds002", 20, 1},
		{"zhangds003", 40, 0},
		{"zhangds004", 12, 1},
	};

	for (int i = 0; i < 4; i++)
	{
		printf("姓名:%s, 年龄:%d, 性别:%hd \n", a2[i].name, a2[i].age, a2[i].sex);
	}

	// 指针结构体
	struct b1
	{
		char *name;
		int age;
		short int sex;
	} b2 = {"zhangds005", 17, 0}, *b3 = &b2;
	printf("姓名:%s, 年龄:%d, 性别:%hd \n", b3->name, b3->age, b3->sex);

	// 指针数组结构体
	struct d1
	{
		char *name;
		int age;
		short int sex;
	} d2[4] = {
		{"asd001", 18, 1},
		{"asd002", 23, 1},
		{"asd003", 25, 1},
		{"asd004", 27, 1},
	},
	  *d3;
	d3 = d2;
	printf("姓名:%s \n", d3[2].name); // 姓名:asd003

	for (int i = 0; i < 4; i++)
	{
		printf("姓名:%s, 年龄:%d, 性别:%hd \n", d3[i].name, d3[i].age, d3[i].sex);
	}

	// 结构体作为函数参数
	int len = sizeof(stus) / sizeof(struct stu);
	average(stus, len);

	return (0);
}
